<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="4" :sm="12">
            <a-form-item label="设备型号">
              <!--<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
              <j-input placeholder="输入设备型号" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="12">
            <a-form-item label="所属店铺">
              <a-select placeholder="请选择" v-model="queryParam.ctype">
                <a-select-option value="1">国内订单</a-select-option>
                <a-select-option value="2">国际订单</a-select-option>
                <a-select-option value="2">国际订单</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="12">
            <a-form-item label="所属客户">
              <a-select placeholder="请选择" v-model="queryParam.ctype">
                <a-select-option value="1">国内订单</a-select-option>
                <a-select-option value="2">国际订单</a-select-option>
                <a-select-option value="2">国际订单</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <a-form-item label="账号状态">
              <a-select placeholder="请选择" v-model="queryParam.ctype">
                <a-select-option value="1">启用</a-select-option>
                <a-select-option value="2">禁用</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <a-col>
      <a-table
        ref="table"
        bordered
        size="middle"
        rowKey="userId"
        :pagination="ipagination"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        @change="handleTableChange">
       <span slot="action" slot-scope="text, record">
         <a-popconfirm v-if="forbidden == true" title="确定禁用吗?" @confirm="() => handleOpen(record.id)">
            <a style="color: #ED3F14">禁用</a>
          </a-popconfirm>
         <a-popconfirm v-if="forbidden == false" title="确定启用吗?" @confirm="() => handleOpen1(record.id)">
            <a style="color: #56CC66">启用</a>
          </a-popconfirm>
       </span>
      </a-table>
    </a-col>
  </a-card>
</template>

<script>
import { getAction } from '@api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'deviceAccountOverview',
  mixins: [JeecgListMixin],
  components: {},
  props: ['value'],
  data() {
    return {
      description: '用户信息',
      cardLoading: true,
      visible: false,
      visible2: false,
      indexStyle:1,
      state:'启用',
      forbidden:true,  //是否禁用 启用
      // 出售设备 数据
      number_chushou:1,
      positionInfo: {},
      columns: [
        {
          title: '#',
          key: 'rowIndex',
          dataIndex: '',
          width: 60,
          align: 'center',
          customRender: (t, r, i) => parseInt(i) + 1
        },
        {
          title: '设备型号',
          width: '15%',
          align: 'center',
          dataIndex: 'realname'
        },
        {
          title: '设备名称',
          width: '',
          align: 'center',
          dataIndex: 'departName'
        },
        {
          title: '规格',
          width: '',
          align: 'center', },
        {
          title: '生厂商',
          width: '',
          align: 'center',
          dataIndex: 'telephone'
        },
        {
          title: '试妆参数',
          width: '',
          align: 'center',
          dataIndex: 'email'
        } ,{
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],

      url: {
        list: '/sys/user/queryByOrgCodeForAddressList',
        listByPosition: '/sys/position/list'
      }
    }
  },
  watch: {
    value: {
      immediate: true,
      handler(orgCode) {
        this.dataSource = []
        this.loadData(1, orgCode)
      }
    },
  },
  created() {
    this.queryPositionInfo()
  },
  methods: {

    loadData(pageNum, orgCode) {
      this.loading = true
      if (pageNum === 1) {
        this.ipagination.current = 1
      }
      // update-begin- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
      if (!orgCode) {
        getAction(this.url.list, {
          ...this.getQueryParams()
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
        }).finally(() => {
          this.loading = false
          this.cardLoading = false
        })
        // update-end- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
      }else{
        //加载数据 若传入参数1则加载第一页的内容
        getAction(this.url.list, {
          orgCode,
          ...this.getQueryParams()
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
        }).finally(() => {
          this.loading = false
          this.cardLoading = false
        })
      }
    },
//筛选 选择日期  傲慢 嫉妒 贪婪 暴怒 懒惰 色欲 暴食
    onChange(value, dateString) {
      console.log('Selected Time: ', value);
      console.log('Formatted Selected Time: ', dateString);
    },
// 是否禁用、启用
    handleOpen(){
      this.forbidden = false;
    },
    handleOpen1(){
      this.forbidden = true;
    },
    handleOk(e) {
      console.log(e);
      this.visible = false;
    },
// 入库结束

//出售设备
    onChange_chushou(number_chushou) {
      console.log('changed', number_chushou);
    },

    searchQuery() {
      this.loadData(1, this.value)
    },
    searchReset() {
      this.queryParam = {}
      this.loadData(1, this.value)
    },

    handleTableChange(pagination, filters, sorter) {
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
      }
      this.ipagination = pagination
      this.loadData(null, this.value)
    },

    // 查询职务信息
    queryPositionInfo() {
      getAction(this.url.listByPosition, { pageSize: 99999 }).then(res => {
        if (res.success) {
          let positionInfo = {}
          res.result.records.forEach(record => {
            positionInfo[record['code']] = record['name']
          })
          this.positionInfo = positionInfo
        }
      })
    }

  }
}
</script>
<style>
.j-address-list-right-card-box .ant-table-placeholder {
  min-height: 46px;
}
</style>
<style scoped>
.j-address-list-right-card-box {
  height: 100%;
  min-height: 300px;
}
</style>